package io.geekidea.boot.test.controller;

import io.geekidea.boot.auth.annotation.Permission;
import io.geekidea.boot.common.enums.SysLogType;
import io.geekidea.boot.framework.annotation.Log;
import io.geekidea.boot.framework.page.Paging;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.test.dto.InvoiceRecordDto;
import io.geekidea.boot.test.query.InvoiceRecordQuery;
import io.geekidea.boot.test.service.InvoiceRecordService;
import io.geekidea.boot.test.vo.InvoiceRecordVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 发票申请记录 控制器
 *
 * @author geekidea
 * @since 2025-03-26
 */
@Slf4j
@RestController
@Tag(name = "发票申请记录")
@RequestMapping("/admin/invoiceRecord")
public class InvoiceRecordController {

    @Autowired
    private InvoiceRecordService invoiceRecordService;

    /**
     * 添加发票申请记录
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    @Operation(summary = "添加发票申请记录")
    @PostMapping("/addInvoiceRecord")
    @Permission("invoice:record:add")
    public ApiResult addInvoiceRecord(@Valid @RequestBody InvoiceRecordDto dto) {
        log.info("添加发票申请记录：{}", dto);
        boolean flag = invoiceRecordService.addInvoiceRecord(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改发票申请记录
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    @Operation(summary = "修改发票申请记录")
    @PostMapping("/updateInvoiceRecord")
    @Permission("invoice:record:update")
    public ApiResult updateInvoiceRecord(@Valid @RequestBody InvoiceRecordDto dto) {
        log.info("修改发票申请记录：{}", dto);
        boolean flag = invoiceRecordService.updateInvoiceRecord(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除发票申请记录
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    @Operation(summary = "删除发票申请记录")
    @PostMapping("/deleteInvoiceRecord/{id}")
    @Permission("invoice:record:delete")
    public ApiResult deleteInvoiceRecord(@PathVariable Long id) {
        log.info("删除发票申请记录：{}", id);
        boolean flag = invoiceRecordService.deleteInvoiceRecord(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取发票申请记录详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取发票申请记录详情")
    @PostMapping("/getInvoiceRecord/{id}")
    @Permission("invoice:record:info")
    public ApiResult<InvoiceRecordVo> getInvoiceRecord(@PathVariable Long id) {
        log.info("获取发票申请记录详情：{}", id);
        InvoiceRecordVo invoiceRecordVo = invoiceRecordService.getInvoiceRecordById(id);
        return ApiResult.success(invoiceRecordVo);
    }

    /**
     * 获取发票申请记录分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取发票申请记录分页列表")
    @PostMapping("/getInvoiceRecordPage")
    @Permission("invoice:record:page")
    public ApiResult<InvoiceRecordVo> getInvoiceRecordPage(@Valid @RequestBody InvoiceRecordQuery query) {
        log.info("获取发票申请记录分页列表：{}", query);
        Paging<InvoiceRecordVo> paging = invoiceRecordService.getInvoiceRecordPage(query);
        return ApiResult.success(paging);
    }

}
